﻿using System;
using System.Linq;
using XpressNews.SvcRef.CateMgmt;
using XpressNews.SvcRef.NewsMgmt;

namespace XpressNews
{
    public partial class PageArticlesByCategory : System.Web.UI.Page
    {
        private ServiceNewsManagementClient cNews;
        private ServiceCategoryManagementClient cCate;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadData();
            }
        }

        private void loadData()
        {
            String catId = Request.QueryString["catId"];
            if (String.IsNullOrEmpty(catId))
            {
                catId = "cat0001";
            }
            cCate = new ServiceCategoryManagementClient("catBasicHttpBinding");
            Category cate = cCate.searchCategoryById(catId);
            lblCatName.Text = cate.catName;
            cCate.Close();

            cNews = new ServiceNewsManagementClient("newsWsHttpBinding");
            var lstNews = cNews.RetrieveNewsByCategoryID(catId);           
            
            rptNews.DataSource = lstNews;
            rptNews.DataBind();

            //int numberOfNews = 3;
            //var l = cNews.RetrieveLatestNewsByCategory(catId);

            cNews.Close();
        }
    }
}